import { dataimpService } from '~/config/server';
import { NetService } from '~/utils/net.service';
import { Inject, Debounce } from '~/core/decorator';
import { FilterService } from "~/utils/filter.service";

export class StrategyConfigService {
  @Inject(NetService)
  private netService: NetService;

  /**
   * 获取支持的策略字段
   */
  public getStrategyFields() {
    return this.netService.send({
      server: dataimpService.strategyConfigController.getStrategyFields
    });
  }

  /**
   * 创建策略
   */
  @Debounce()
  public createStrategy(data) {
    return this.netService.send({
      server: dataimpService.strategyConfigController.createStrategy,
      data,
      loading: true
    });
  }

  /**
   * 修改策略
   */
  @Debounce()
  public updateStrategy(data) {
    return this.netService.send({
      server: dataimpService.strategyConfigController.updateStrategy,
      data,
      loading: true
    });
  }
  /**
   * 作废/终止
   * @param data
   */
  public updateStrategyStatus(data) {
    return this.netService.send({
      server: dataimpService.strategyConfigController.updateStrategyStatus,
      data: {
        id: data.id,
        strategyStatus: data.strategyStatus
      },
    });
  }

  /**
   * 分页查询策略
   */
  public queryStrategyConfigPage(data, page) {
    return this.netService.send({
      server: dataimpService.strategyConfigController.queryStrategyConfigPage,
      data: {
        name: data.name,
        strategyStatus: data.strategyStatus,
        executionFrequency: data.executionFrequency,
        latelyDatetimeMin: FilterService.dateRanageFormat(data.startDate).start,
        latelyDatetimeMax: FilterService.dateRanageFormat(data.startDate).end
      },
      page
    });
  }
  /**
   * 通过ID获取策略
   * @param data
   */
  public getOneById(id) {
    return this.netService.send({
      server: dataimpService.strategyConfigController.getOneById,
      data: {
        id
      }
    });
  }

  /**
   * 通过ID删除策略
   * @param data
   */
  public delete(id) {
    return this.netService.send({
      server: dataimpService.strategyConfigController.delete,
      data: {
        id
      }
    });
  }

  /**
   * 策略执行记录查看
   */
  public queryStrategyConfigDetailData(data, page) {
    return this.netService.send({
      server: dataimpService.strategyConfigController.queryStrategyConfigDetailData,
      data: {
        name: data.name,
        caseNumber: data.caseNumber,
        customerName: data.customerName,
        runningTimeMin: data.checkTime.length ? FilterService.dateTimeFormat(data.checkTime[0]) : '',
        runningTimeMax: data.checkTime.length ? FilterService.dateTimeFormat(data.checkTime[1]) : '',
        id: data.id
      },
      page
    });
  }

  /**
   * 获取支持的策略字段
   */
  public getLabelNameFields() {
    return this.netService.send({
      server: dataimpService.strategyConfigController.getLabelNameFields
    });
  }

}
